//首页
import React, { useEffect, useState } from 'react';
import { RichText, View } from '@tarojs/components';
import './index.less';
import TitleBar from 'src/components/titleBar';
import Taro, { useRouter } from '@tarojs/taro';
import BottomContainer from '@/src/components/bottomContainer';
import LoadingSpinner from '@/src/components/loadingSpinner';
import { observer } from 'mobx-react-lite';
import CommonBlank from '@/src/components/pageBlank';
import store from '@/src/store';
import { reviewArticleFun } from '@/src/common/method/activityFun';
import { formatRichText } from '@/src/common/util/util';
interface RouteParams {
  activityId: string;
  [key: string]: string | undefined;
}
//活动回顾
const Review = () => {
  const { params } = useRouter<RouteParams>();
  const [paddingTop, setPaddingTop] = useState<number>();

  const [dataList, setDataList] = useState([]);
  const [loadingText, setLoadingText] = useState<any>('加载中...');

  useEffect(() => {
    reviewArticleFun({
      activityId: params.activityId,
      userId: Taro.getStorageSync('userId'),
    }).then((res: any) => {
      setLoadingText('');

      if (res.code === '0') {
        //将返回的内容&amp;替换为&
        setDataList(res.data.activityReviewArticle.replace(/&amp;/g, '&'));
      }
      console.log(res.data.activityReviewArticle.length, 'res===活动回顾');
    });
  }, []);
  return (
    <View
      className="mine-review-container"
      style={{ paddingTop: `${store.commonStore.safeAreaTop}rpx` }}
    >
      <TitleBar showLeftBack={true} title="活动回顾"></TitleBar>
      <View className="mine-review-content">
        <RichText className="article-desc" nodes={formatRichText(dataList)} />
      </View>

      {loadingText === '' && dataList.length === 0 && (
        <CommonBlank visible desc={'暂无内容'} />
      )}

      <LoadingSpinner text={loadingText} />
      <BottomContainer />
    </View>
  );
};

export default observer(Review);
